@extends('layouts.default') @section('main')
<link rel="stylesheet" href="{{URL::asset('js/')}}/kindeditor-4.1.7/themes/default/default.css" />
<link rel="stylesheet" href="{{URL::asset('js/')}}/kindeditor-4.1.7/plugins/code/prettify.css" />
<script src="{{URL::asset('js/')}}/kindeditor-4.1.7/kindeditor.js" type="text/javascript"></script> 
<script charset="utf-8" src="{{URL::asset('js/')}}/kindeditor-4.1.7/lang/zh_CN.js"></script> 
<script charset="utf-8" src="{{URL::asset('js/')}}/kindeditor-4.1.7/plugins/code/prettify.js"></script>
<script type="text/javascript" src="{{URL::asset('js/')}}/ajaxfileupload.js"></script>
<script type="text/javascript" src="{{URL::asset('js/')}}/common.js"></script>
<script src="{{URL::asset('js/My97DatePicker/')}}/WdatePicker.js"></script>
<script src="{{URL::asset('js/My97DatePicker/')}}/WdatePicker.js"></script>

<script>
KindEditor.ready(function(K) {

		var editor1 = K.create('#activity_content,#activity_description', {
			uploadJson: "{{url('kindedit/upload')}}",
			fileManagerJson: "{{url('kindedit/manager')}}",
			allowFileManager: true,
			afterBlur: function() {
				this.sync();
			},
			items: ['source', '|', 'undo', 'redo', '|', 'cut', 'copy', 'paste', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', 'image', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'table', 'hr', 'emoticons', 'pagebreak', 'anchor', 'link', 'unlink', '|']
		});
		
});
</script>
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a href="{{url('home')}}" title="返回首页" class="tip-bottom"><i
				class="icon-home"></i> 首页</a> <a href="{{url('activityprojectvideo/index')}}"
				class="tip-bottom">活动视频管理</a> <a href="#" class="current">编辑活动视频</a>
		</div>
	</div>
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span9">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-align-justify"></i>
						</span>
						<h5>编辑活动视频</h5>
					</div>
					<div class="widget-content nopadding">
						<form action="{{url('activityprojectvideo/update')}}" method="post"
							class="form-horizontal" id="activityForm">

                            <div class="control-group" id="activity_type">
                                <label class="control-label"><span class="redD">*</span>活动类型 :</label>
                                <div class="controls">
                                    <select name="activity_type" class="span11" id="activity_type">
                                        <option value="">请选择</option>
                                        @foreach($activity_type as $v)
                                            <option is_roadshow="{{$v->is_roadshow}}" is_activity="{{$v->is_activity}}" @if($video->activity_type==$v->code) selected="selected" @endif value="{{$v->code}}">{{$v->name}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>

							<div class="control-group" id="activity_id" @if($nowType->is_activity==0)style="display: none"@endif>
								<label class="control-label">活动名称 :</label>
								<div class="controls">
									<select name="activity_id" class="span11" id="activity" >
									<option value="">请选择</option>
                                        @foreach($activities as $v)
                                            <option  @if($video->activity_id==$v->id) selected="selected" @endif value="{{$v->id}}">{{$v->subject}}</option>
                                        @endforeach
					                </select>
								</div>
							</div>
							<div class="control-group" id="project_id" @if($nowType->is_roadshow==0)style="display: none"@endif>
								<label class="control-label">项目名称 :</label>
								<div class="controls">
									<select name="project_id" class="span11" id="project">
									<option value="">请选择</option>
                                        @foreach($projects as $v)
                                            <option  @if(isset($v->project) && $video->project_id==$v->project->id) selected="selected" @endif value="{{$v->id}}">@if(isset($v->project)){{$v->project->subject}}@endif</option>
                                        @endforeach
					                </select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">视频地址 :</label>
								<div class="controls">
									<input type="text" class="span11" name="app_path" value="{{$video->app_path}}"
										placeholder="视频地址" />
								</div>
							</div>
							{{--<div class="control-group">--}}
								{{--<label class="control-label">APP视频地址 :</label>--}}
								{{--<div class="controls">--}}
									{{--<input type="text" class="span11" name="app_path" value="{{$video->app_path}}"--}}
										{{--placeholder="APP视频地址" />--}}
								{{--</div>--}}
							{{--</div>--}}
							<div class="control-group">
								<label class="control-label"><span class="redD">*</span>标题 :</label>
								<div class="controls">
									<input type="text" class="span11" name="subject" value="{{$video->subject}}"
										placeholder="标题" />
								</div>
							</div>
							{{--<div class="control-group">--}}
								{{--<label class="control-label">副标题 :</label>--}}
								{{--<div class="controls">--}}
									{{--<input type="text" class="span11" name="title" value="{{$video->title}}"--}}
										{{--placeholder="副标题" />--}}
								{{--</div>--}}
							{{--</div>--}}
							<div class="control-group">
								<label class="control-label"><span class="redD">*</span>视频图片 :</label>
								<div class="controls">
									<input type="hidden" class="span11" name="image" value="{{$video->image}}"
										placeholder="视频图片" />
                                    <img src="{{getImage($video->image)}}" width="120px" name="image" height="120px"/>

                                    <a href="javascript:void(0);" id="uploadPhotoBtn"   onclick="javascript:openBrowse('uploadPhotoBtn','uploadPhoto');">点击上传(图片大小不小于h:876像素×w:1440像素)</a>
                                        <input type="file" id="uploadPhoto" style="display:none" name="myfile" size="10" onchange="fileUpload('uploadPhoto','image')"/>
								</div>
							</div>
							{{--<div class="control-group">--}}
								{{--<label class="control-label">发布时间 :</label>--}}
								{{--<div class="controls">--}}
									{{--<input type="text" class="span11" name="pubdate" value="{{date('Y-m-d H:i:s',$video->pubdate)}}" onfocus="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"--}}
										{{--placeholder="发布时间" />--}}
								{{--</div>--}}
							{{--</div>--}}
							<div class="control-group">
								<label class="control-label">描述 :</label>
								<div class="controls">
									<textarea class="span11" name="description">{{$video->description}}</textarea>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label"><span class="redD">*</span>内容 :</label>
								<div class="controls">
									<textarea id="activity_content" name="content" style="width: 450px; height: 240px;">{{$video->content}}</textarea>
								</div>
							</div>
							{{--<div class="control-group">--}}
								{{--<label class="control-label">二维码地址 :</label>--}}
								{{--<div class="controls">--}}
									{{--<input type="text" class="span11" name="qrcode" value="{{$video->qrcode}}"--}}
										{{--placeholder="二维码地址" />--}}
								{{--</div>--}}
							{{--</div>--}}
							{{--<div class="control-group">--}}
								{{--<label class="control-label">播放量 :</label>--}}
								{{--<div class="controls">--}}
									{{--<input type="text" class="span11" name="views" value="{{$video->views}}"--}}
										{{--placeholder="播放量" />--}}
								{{--</div>--}}
							{{--</div>--}}
							{{--<div class="control-group">--}}
								{{--<label class="control-label">视频时长 :</label>--}}
								{{--<div class="controls">--}}
									{{--<input type="text" class="span11" name="times" value="{{$video->times}}"--}}
										{{--placeholder="视频时长" />--}}
								{{--</div>--}}
							{{--</div>--}}
							<div class="control-group">
								<label class="control-label">点赞 :</label>
								<div class="controls">
									<input type="text" class="span11" name="likes" value="{{$video->likes}}"
										placeholder="点赞" />
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">点击量 :</label>
								<div class="controls">
									<input type="text" class="span11" name="click_views" value="{{$video->click_views}}"
										placeholder="点击量" />
								</div>
							</div>
                            <div class="control-group">
                                <label class="control-label">排序 :</label>
                                <div class="controls">
                                    <input type="text" class="span11" name="sort" value="{{$video->sort}}"
                                           placeholder="排序" />
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label"><span class="redD">*</span>是否热门 :</label>
                                <div class="controls">
                                    <input type="radio"  name="hot"  value="1" @if($video->hot==1)checked="checked"@endif/>热门
                                    <input type="radio"  name="hot" value="0" @if($video->hot==0)checked="checked"@endif />不热门
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label"><span class="redD">*</span>是否置顶 :</label>
                                <div class="controls">
                                    <input type="radio"  name="top"  value="1" @if($video->top==1)checked="checked"@endif/>置顶
                                    <input type="radio"  name="top" value="0" @if($video->top==0)checked="checked"@endif />不置顶
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label"><span class="redD">*</span>是否精彩 :</label>
                                <div class="controls">
                                    <input type="radio"  name="wonderful"  value="1" @if($video->wonderful==1)checked="checked"@endif/>精彩
                                    <input type="radio"  name="wonderful" value="0" @if($video->wonderful==0)checked="checked"@endif />不精彩
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label"><span class="redD">*</span>状态 :</label>
                                <div class="controls">
                                    <input type="radio"  name="status"  value="1" @if($video->status==1)checked="checked"@endif/>正常
                                    <input type="radio"  name="status" value="-1" @if($video->status==-1)checked="checked"@endif />禁用
                                </div>
                            </div>


                            <div class="control-group">
                                <label class="control-label">备注 :</label>
                                <div class="controls">
                                    <input type="text" class="span11" name="remark" placeholder="审核不通过或禁用的备注" value="{{$video->remark}}"  />
                                </div>
                            </div>


                            <div id="user" @if($nowType->is_activity==1) style="display: none;" @endif>
                                <div class="control-group">
                                    <label class="control-label">用户姓名或手机号的一部分供模糊搜索 :</label>
                                    <div class="controls">
                                        <input type="text" class="span11" name="user_search" value="" placeholder="输入用户姓名或手机号的一部分，按下Enter键，搜索结果将出现在下面的多选框中，供选择" />
                                    </div>
                                </div>

                                <div class="control-group">
                                    <label class="control-label">视频拥有人 :</label>
                                    <div class="controls">
                                        <select name="uid" id="uid">
                                            @if($user)
                                                <option value="{{$user->uid}}">{{$user->realname or $user->nickname}}</option>
                                            @else
                                                <option value="">请按上面输入框的说明生成选项</option>
                                            @endif
                                        </select>
                                    </div>
                                </div>
                            </div>


                            <div class="control-group">
                                <label class="control-label">视频关键字 :</label>
                                <div class="controls">
                                    <input type="text" class="span11" name="tag"  value="{{$tagNames}}"  placeholder="视频关键字，若有多个关键字，则用逗号隔开" />
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label">视频创建时间 :</label>
                                <div class="controls">
                                    <input type="text" class="span11" name="created_at" value="{{date('Y-m-d H:i:s',$video->created_at)}}" placeholder="报名开始时间" onfocus="WdatePicker({startDate:'{{date('Y-m-d H:i:s',$video->created_at)}}',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})" />
                                </div>
                            </div>

							<div class="form-actions">
								<input type="hidden" name="id" value="{{$video->id}}">
								<button type="button" id="doSave" class="btn btn-success">保存</button>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript" src="{{URL::asset('js/')}}/common.js"></script>

<script>

    $("input[name='user_search']").keydown(function(event) {
        if (event.which == "13"){
            var param = {};
            param['user_search'] = $(this).val();
            ajaxRequest(param, '/project/user-search', function (data) {
                if (data.status) {
                    var html = '<option value="">请选择</option>';
                    $.each(data.message, function (i, n) {
                        if(n.realname){
                            html += "<option value='" + n.uid + "'>" + n.realname + "</option>";
                        }else{
                            html += "<option value='" + n.uid + "'>" + n.nickname + "</option>";
                        }
                    });
                    $("#uid").html(html);
                    alert('恭喜，已经生成选项,请选择所需要的用户');
                } else {
                    var html = '<option value="">请按上面输入框的说明生成选项</option>';
                    $("#uid").html(html);
                    alert(data.message);
                }
            });
        }
    });

    $("select[name=activity_type]").change(function(){
        var is_roadshow=$(this).find("option:selected").attr('is_roadshow');
        var is_activity=$(this).find("option:selected").attr('is_activity');
        var activity_type=$(this).val();

        if(is_roadshow==1 && is_activity==1){
            $("#activity_id").show();
            $("#project_id").show();
            $("#user").hide();
        }

        if(is_activity!=1 && is_roadshow!=1){
            $("#activity_id").hide();
            $("#project_id").hide();
            $("#user").hide();
        }

        if(is_activity==1 && is_roadshow!=1){
            $("#activity_id").show();
            $("#project_id").hide();
            $("#user").hide();
        }

        if(is_activity==0 && is_roadshow==0){
            $("#user").show();
        }

        param={};
        param['activity_type'] = activity_type;

        ajaxRequest(param,"{{url('activityprojectvideo/search-activity')}}",function(data){
            if(data.status){
                var html = '<option value="">请选择</option>';
                $.each(data.message, function(i, n) {
                    html += "<option value='"+n.id+"'>"+n.subject+"</option>";
                });
                $("#activity").html(html);
            }else{
                var html = '<option value="">请选择</option>';
                $("#activity").html(html);
            }
        });

    })

$("#doSave").click(function(){
	ajaxRequest($('#activityForm').serializeArray(),$('#activityForm').attr('action'),function(data){
		if(data.status){
            alert(data.message);
            window.location.href = data.forwardUrl;
		}else{
			alert(data.message);
		}
	});
});
var activity_id = {{$video->activity_id}};
var project_id = {{$video->project_id}};
if(activity_id > 0){
	$.post("{{url('activityprojectvideo/activityprojects')}}", {
		aid: activity_id
	}, function(data) {
		if (data.status) {
			var html = '<option value="">请选择</option>';
			$.each(data.message, function(i, n) {
				var selected = project_id == n.id ? 'selected="selected"' : '';
				html += "<option value='"+n.id+"' "+selected+">"+n.subject+"</option>";
			});
			$("#project").html(html);
		}
	}, 'json');
}
$("#activity").change(function() {
	$("#project").empty();
	$.post("{{url('activityprojectvideo/activityprojects')}}", {
		aid: $(this).val()
	}, function(data) {
		if (data.status) {
			var html = '<option value="">请选择</option>';
			$.each(data.message, function(i, n) {
				html += "<option value='"+n.id+"'>"+n.subject+"</option>";
			});
			$("#project").html(html);
		}
	}, 'json');
});
</script>
@stop
